<template>
	<view>
		<view class="box">
			<view class="box-top">
				<img class='arrow' @click='retu' src='http://127.0.0.1:7001/public/activity/jiantou.png'>
				<span class='activity'>编辑活动</span>
				<span class='signup' @click="signup">发布</span>
			</view>
			<!-- 类型 -->
			<view class="activitytype" style="display: flex;">
				<view class="activitytype1">类型</view>
				<view style="width: 69%;"></view>
				<view class="activitytype2">
					<span v-if="isType">KTV</span>
					<span v-if="istype">{{userList[aIndex].hobby}}</span>
					<picker mode="selector" :range="userList" range-key="hobby" @change="checkStudent" :value="aIndex"
						class="right">
						<img class='youarrow' src='http://127.0.0.1:7001/public/activity/youjiantou.png'>
					</picker>
				</view>
			</view>
			<!-- 时间 -->
			<view class="activitytype" style="display: flex;">
				<view class="activitytype1">时间</view>
				<view style="width: 43%;"></view>
				<view class="activitytype2">
					<span>
						<span v-if="isTime">2022-09-06 20:20</span>
						<span v-if="istime">{{this.timetext.year}}-{{timetext.month}}-{{timetext.day}}
							{{timetext.hour}}:{{timetext.minute}}</span>
					</span>
					<img class='youarrow1' @click="timeshow = true"
						src='http://127.0.0.1:7001/public/activity/youjiantou.png'>
					<u-picker mode="time" @confirm='confirm' v-model="timeshow" :params="params" @click="release()">
					</u-picker>
				</view>
			</view>
			<view class="shuru">
				<u-input v-model="value" :type="type" :border="border" :height="height" :auto-height="autoHeight" />
			</view>
			<u-toast ref="uToast" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 时间
				isTime: true,
				istime: false,
				timeshow: false,
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
				},
				timetext: '',
				timetitle: '',

				// 类型
				userList: [],
				aIndex: 0,
				typeArray: [],
				isType: true,
				istype: false,
				// 介绍
				value: '',
				type: 'textarea',
				border: false,
				height: 700,
				autoHeight: true,
				id: undefined
			}
		},
		onLoad(option) {
			this.$api.WhjUser().then(res => {
				this.userList = res.data
				console.log(this.userList)
			})
			this.id = option.id

		},
		methods: {
			//发布
			signup() {
				if (this.value == '') {
					this.$refs.uToast.show({
						title: '请输入活动内容',
						type: 'default'
					})
				} else if (this.value != '') {
					this.$api.whjreleaseaa({
						id: this.id,
						time: this.timetitle,
						hobby: this.typeArray.hobby,
						interest: this.value,
						hobbyurl: this.typeArray.hobbyurl
					}).then(res => {
						if (res.code == 200) {
							this.value = '',
								this.$refs.uToast.show({
									title: '更改成功',
									type: 'success',
									url: '/pages/person/Discount/Discount'
								})
						}
					})
				}
			},
			retu() {
				uni.navigateBack({
					delta: 1
				})
			},
			// 时间
			confirm(e) {
				this.timetext = e
				// console.log(e)
				this.Isitem = true
				this.itemtext = false
				this.timetitle =
					`${this.timetext.year}-${this.timetext.month}-${this.timetext.day} ${this.timetext.hour}:${this.timetext.minute}`
				// console.log(this.timetitle)
				this.isTime = false
				this.istime = true
			},
			// 类型
			checkStudent(e) {
				this.aIndex = e.detail.value
				this.typeArray = this.userList[this.aIndex]
				// console.log(this.typeArray)
				this.isType = false
				this.istype = true
			},

		}
	}
</script>

<style lang="scss">
	.box {
		width: 100%;
		height: 100vh;
		background: #F2F2F2;

		.box-top {
			width: 100%;
			height: 10%;
			border-bottom: 1px solid #f7cb88;
			position: relative;
			background: white;

			.arrow {
				width: 3%;
				height: 25%;
				position: absolute;
				top: 41%;
				left: 5%;
			}

			.activity {
				font-size: 35upx;
				text-align: center;
				display: block;
				line-height: 140upx;

			}

			.signup {
				font-size: 35upx;
				position: absolute;
				top: 38%;
				right: 5%;
				color: coral;
			}
		}
	}

	// 类型
	.activitytype {
		width: 100%;
		height: 100upx;
		background: white;
		border-bottom: 1px solid #eeebeb;

		.activitytype1 {
			font-size: 18px;
			line-height: 90upx;
			margin-left: 10px;
			color: #999;
		}

		.activitytype2 {
			.right {
				float: left;

				.youarrow {
					width: 17px;
					height: 20px;
					margin-left: 10px;
					margin-top: 18px;
					float: left;
				}
			}

			.youarrow1 {
				width: 17px;
				height: 20px;
				margin-left: 8px;
				margin-top: 17px;
				float: left;
			}

			span {
				font-size: 18px;
				line-height: 100upx;
				display: block;
				float: left;
			}


		}
	}

	// 输入
	.shuru {
		width: 100%;
		height: 30%;
		background: white;
	}
</style>
